define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'resource/teacher/index' + location.search,
                    add_url: 'resource/teacher/add',
                    edit_url: 'resource/teacher/edit',
                    del_url: 'resource/teacher/del',
                    multi_url: 'resource/teacher/multi',
                    import_url: 'resource/teacher/import',
                    table: 'teacher',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                search:false,
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'head_avatar', title: __('Head_avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'name', title: __('老师信息'), operate: 'LIKE',align: 'left',formatter:function(value,row,index){return row.is_home_text+'<p>姓名:'+value + "</p><p>性别:" + row.sex_data+'</p><p>常州地址:'+row.city+'</p>'; }},
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        {field: 'state', title: __('State'), searchList: {"自有教练":__('自有教练'),"外聘教练":__('外聘教练')}, formatter: Table.api.formatter.normal},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
                        {field: 'code_address', title: __('Code_address'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image,formatter:function(value,row,index){return '<a href="javascript:"><img class="img-sm img-center" src="'+value+'"></a><a download="beautifulGirl" href="'+value+'">下载</a>' ; }},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        /*{field: 'admin.nickname', title: __('Principal'), operate: 'LIKE'},*/
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        index1: function () {
            window.myevents = {
                'click .btn-select':function(e,value,row,index){
                    window.parent.$('#c-teacher_id').val(row.id);
                    window.parent.$('#c-teacher_title').val(row.name);
                    var index = parent.layer.getFrameIndex(window.name);
                    console.log(parent.layer.close(index));
                }
            }

            function myformatter(){
                return [
                    '<button class="btn btn-xs btn-primary btn-select"  type="button">选择</button>'
                ].join("");
            }
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'resource/teacher/index' + location.search,
                    add_url: 'resource/teacher/add',
                    edit_url: 'resource/teacher/edit',
                    del_url: 'resource/teacher/del',
                    multi_url: 'resource/teacher/multi',
                    import_url: 'resource/teacher/import',
                    table: 'teacher',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                search:false,
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'head_avatar', title: __('Head_avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'name', title: __('老师信息'), operate: 'LIKE',align: 'left',formatter:function(value,row,index){return row.is_home_text+'<p>姓名:'+value + "</p><p>性别:" + row.sex_data+'</p><p>常州地址:'+row.city+'</p>'; }},
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        {field: 'state', title: __('State'), searchList: {"自有教练":__('自有教练'),"外聘教练":__('外聘教练')}, formatter: Table.api.formatter.normal},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
                        {field: 'code_address', title: __('Code_address'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image,formatter:function(value,row,index){return '<a href="javascript:"><img class="img-sm img-center" src="'+value+'"></a><a download="beautifulGirl" href="'+value+'">下载</a>' ; }},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        /*{field: 'admin.nickname', title: __('Principal'), operate: 'LIKE'},*/
                        {field: 'operate', title: __('Operate'), table: table,events:myevents,formatter:myformatter}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
